package com.nuo.modules.news.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuo.common.utils.PageUtils;
import com.nuo.common.utils.Query;
import com.nuo.modules.news.dao.NewsDao;
import com.nuo.modules.news.entity.NewsEntity;
import com.nuo.modules.news.service.NewsService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("newsService")
public class NewsServiceImpl extends ServiceImpl<NewsDao, NewsEntity> implements NewsService {

    // http://124.221.91.8:12345
    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String title = (String) params.get("title");
        String category = (String) params.get("category");

        IPage<NewsEntity> page = this.page(
                new Query<NewsEntity>().getPage(params),
                new LambdaQueryWrapper<NewsEntity>()
                        .like(StringUtils.isNotBlank(title), NewsEntity::getTitle, title)
                        .eq(StringUtils.isNotBlank(category), NewsEntity::getCategory, category).orderByDesc(NewsEntity::getCreateTime)
        );

        return new PageUtils(page);
    }

}
